﻿using System;
using System.Windows.Forms;
using XCI.Core;
using XCI.Helper;

namespace XCI.Windows
{
    public partial class FrmHome : BaseForm
    {
        public static string Code = "home";
        private WidgetObject widgetObject;

        public FrmHome()
        {
            InitializeComponent();
        }

        private async void FrmHome_Load(object sender, EventArgs e)
        {
            barMainMenu.Visible = AppDefaultSettings.AllowCustomWidgetSetting;
            widgetObject = new WidgetObject(widgetView1, Code);
            await widgetObject.LoadAsync();
        }

        private async void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            await widgetObject.SaveLayoutAsync();
            await widgetObject.SaveItemsAsync();
            btnSave.Enabled = false;
            MessageBoxHelper.ShowMessage("保存成功");
        }

        private async void btnCustom_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            await widgetObject.SaveLayoutAsync();
            widgetObject.Design();
            await widgetObject.LoadAsync();
        }

        private async void btnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            await widgetObject.LoadAsync();
        }

        private void widgetView1_DocumentClosed(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndSizing(object sender, DevExpress.XtraBars.Docking2010.Views.LayoutEndSizingEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndDragging(object sender, EventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndFloating(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndDocking(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndStackGroupDragging(object sender, DevExpress.XtraBars.Docking2010.Views.StackGroupDraggingEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_Dragging(object sender, MouseEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_BeginSizing(object sender, DevExpress.XtraBars.Docking2010.Views.LayoutBeginSizingEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_EndDocumentsHostDocking(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            btnSave.Enabled = true;
        }

        private void widgetView1_Floating(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            btnSave.Enabled = true;
        }
    }
}
